package com.learn.designPatterns.behavioral.interpreter;

import java.util.StringTokenizer;

/**
 * @classname:
 * @Description:
 * @author: yfpu
 * @Date: 2018-09-17 17:30
 */
public class TerminalExpression extends Expression{

    private String literal = null;

    public TerminalExpression(String literal) {
        this.literal = literal;
    }

    @Override
    public boolean interpret(String str) {
        StringTokenizer stringTokenizer = new StringTokenizer(str);
        while (stringTokenizer.hasMoreTokens()) {

            String test = stringTokenizer.nextToken();
            if (test.equals(literal))
                return true;
        }
        return false;
    }
}
